package br.com.brasilprojetos.geometric;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

/**
 * 
 * Create a geometric form
 * 
 * */
public class Geometric extends GameEntity {
	
	/***/
	private int mSides;

	@Override
	/**
	 * based in the number of sides create the vertice buffer
	 */
	protected void populateVertice(){
		
		//make all geometric point to (1, 0) when rotation in equal to 0
		double angleAux = 0;
		if((int)(0.75 * this.mSides) == (0.75 * this.mSides))
		{
			angleAux = Math.PI / this.mSides;
		}

		double angle;
		this.mVertices = new float[this.mSides * 3];
		for (int i = 0, s = 1; i < this.mVertices.length; i = i + 3, s++) {

			angle = 2.0 * Math.PI * s / this.mSides;
			angle += angleAux;
			
			this.mVertices[i] = (float) Math.cos(angle);
			this.mVertices[i + 1] = (float) Math.sin(angle);
			this.mVertices[i + 2] = (0);
		}
	};

	public Geometric(float pX, float pY) {
		
		this(pX, pY, 4);
	}

	public Geometric(float pX, float pY, int pSides) {

		this(pX, pY, pSides, 100);
	}

	public Geometric(float pX, float pY, int pSides, float pScale) {
		
		super();
		this.setPosition(pX, pY);
		this.setScale(pScale, pScale);
		
		this.setmSides(pSides);
		this.createBuffer();
	}

	// ----- Getters and Setters --- ///
	public int getmSides() {
		return mSides;
	}

	public void setmSides(int mSides) {
		this.mSides = mSides;
	}
}
